﻿<%@ Page Title="淘汰品设置" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/css/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
    <link href="../assets/img/validate/validate.css" rel="stylesheet">
    <link href="../assets/css/plugins/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet" />
    <link href="../assets/js/plugins/jQuery-DataTables/extensions/FixedColumns/css/fixedColumns.bootstrap.min.css" rel="stylesheet" />
    <link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
    <link href="../assets/css/system/pageDefault.css" rel="stylesheet" />

    <style type="text/css">
        .modal-dialog {
            width: 600px;
            margin: 30px auto;
        }
    </style>

</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <%-- 按钮--%>
            <div class="btns-container"></div>
            <%--新增弹出框begin--%>
            <div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content animated bounceInRight">
                        <div class="modal-header">
                            <span class="editTitle">增加淘汰品</span>
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span> <span class="sr-only">关闭</span> </button>
                        </div>
                        <div id="message" style="display: none"></div>
                        <div class="modal-body clearfix">
                            <form class="form-horizontal">
                                <div class="form-group">
                                    <div class="col-sm-1 text-right no-padding">
                                        <label class="control-label input-sm">货号:</label>
                                    </div>
                                    <div class="col-sm-11">
                                        <textarea rows="5" style="width: 98%" id="MaterialList"></textarea>
                                    </div>
                                </div>
                            </form>
                            <br />
                        </div>
                        <div class="modal-footer">
                            <button type="button" id="addModuleBtn" class="btn btn-primary">保存</button>
                            <button type="button" id="closeAddBox" class="btn btn-white" data-dismiss="modal">关闭</button>
                        </div>
                    </div>
                </div>
            </div>
            <%--新增弹出框end--%>
            <%--查询条件begin--%>
            <div class="condition-container" style="overflow: visible;">
                <form class="form-horizontal">
                    <div class="row">
                        <div class="form-group col-sm-3">
                            <label class="control-label" style="float: left">货号</label>
                            <div style="width: 160px; float: left;">
                                <div class="input-group text-center">
                                    <input type="text" class="form-control" placeholder="请输入货号" id="search-MaterialIDs">
                                    <div class="input-group-btn no-padding">
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu"></ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <%--查询条件end--%>
            <div class="table-container">
                <table class="table table-bordered  table-select tableReturPlan"></table>
            </div>
        </div>
    </div>

</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/jquery-ui-1.10.4.min.js"></script>
    <script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
    <script src="../assets/img/validate/learunui-validator.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>
    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/plugins/iCheck/icheckAll.js"></script>
    <script src="../assets/js/plugins/bootstrap-suggest/bootstrap-suggest.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-suggest/itemSuggest.js"></script>


    <script src="../assets/js/plugins/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-select/bootstrap-select.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-select/i18n/defaults-zh_CN.min.js"></script>


    <script src="../assets/js/plugins/jQuery-DataTables/media/js/jquery.dataTables.js"></script>
    <script src="../assets/js/plugins/jQuery-DataTables/media/js/dataTables.bootstrap.js"></script>
    <script src="../assets/js/plugins/jQuery-DataTables/extensions/FixedColumns/js/dataTables.fixedColumns.min.js"></script>
    <script src="../assets/js/plugins/jQuery-DataTables/bootstrap-table-nm.js"></script>

    <script>
        $('document').ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //当前页数
            var page = 1;
            commonUtil.loadBtnList(ModuleID, function () {
                $('#editBtn').attr("disabled", "disabled");
                rScroll();
            });

            var loadParam = {
                MaterialID: $('#search-MaterialIDs').val()
            }

            var itemSuggest_MaterialIDs = new itemSuggest();
            //货号
            //var nmGetMaterialIDs = function () {
            //    var param = {
            //        ShortNames: q_shortNames,
            //        KindNames: q_kindNames,
            //        ItemNames: q_itemNames
            //    }
            //    itemSuggest_MaterialIDs.destroy();
            //    itemSuggest_MaterialIDs.SetBtnHide();
            //    itemSuggest_MaterialIDs.initSuggestPram('search-MaterialIDs', 'ReturPlan', 'GetMaterials', 'MaterialID', 'MaterialID', param);
            //}

            //数据验证
            $('#MaterialList').bind('input propertychange', function (obj) {
                //obj.originalEvent.data  //当前输入值 IE 不能用
                var NowValue = $(this).val().substring(this.value.length - 1, this.value.length);
                //除了逗号，其它都替换掉
                if (NowValue == ',' || NowValue == '，')
                    $(this).val($(this).val().substring(0, $(this).val().length - 1) + ',');
                else if (/[^a-zA-Z0-9\,]/g.test(NowValue))
                    $(this).val($(this).val().substring(0, $(this).val().length - 1));
                //替换中文
                $(this).val($(this).val().replace(/[^\x00-\xff]/g, ''));
            });
            var columns = [
                {
                    title: '<input type="checkbox" id="checkAllPlan" onclick="dataTable.checkAll(this)" />', data: "", width: "30px", className: "check-box text-center", defaultContent: "",
                    render: function (data, type, full, meta) {
                        var html = '<input type="checkbox" class="checkPlan" name="checkPlan" data-index="' + meta.row + '" />';
                        return html;
                    }
                },
                { title: "公司", data: "CompanyID", width: "100px", className: "CompanyID", defaultContent: "" },
                { title: "货号", data: "MaterialID", className: "MaterialID", defaultContent: "" },
            ];
            dataTable.isCheckAll = true;
            //表格初始化
            dataTable.initTable('.table', 'NdwKnockMat', 'GetNdwKnockMatList', loadParam, columns);
            IsCreate = true;
            //获取列表
            var loadList = function () {
                dataTable.loadList(loadParam);
            }
            //查询按钮
            $('.btns-container').on('click', '#btn-search', function () {
                loadParam = {
                    MaterialID: $('#search-MaterialIDs').val()
                }
                loadList();
            });

            //弹窗的保存操作
            $('#addModuleBtn').click(function () {
                var IsOk = false;
                var MateriaValue = $('#MaterialList').val();
                if (MateriaValue == undefined || MateriaValue.trim() == "")
                    swal('数据不能为空！', '', 'error');
                // MateriaValue = MateriaValue.replace(' ', '');
                MateriaValue = MateriaValue.replace('，', ',');
                MateriaValue = MateriaValue.replace(/[^u4e00-u9fa5w]/g, ',');
                MateriaValue = MateriaValue.replace(/[^a-zA-Z0-9\,]/g, '')
                var checkValue = $('#MaterialList').val();

                //!(/[^u4e00-u9fa5w]/g.test(checkValue) && checkValue.indexOf(',') > 0)
                //只能输入 英文字母+数字+逗号
                if (/[^a-zA-Z0-9\,]/g.test(checkValue)) {
                    if (!confirm("检测到有中文/特殊字符输入，将替换成【" + MateriaValue + "】,是否需要修改？"))
                        return;
                }
                $('#MaterialList').val(MateriaValue);
                var successText = "";
                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('NdwKnockMat', "Insert", {
                    //sda,df,3324,,fdsf,ggfd,gdf,fds,,,fds,fds,fsd
                    MaterialID: MateriaValue,
                    ExtrSource: "NM"
                }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal(data, '', 'success');
                        $('#MaterialList').val("");
                        //关闭新建  or 编辑框  
                        $('#closeAddBox').click();
                        //刷新列表
                        loadList();
                    }
                });
            });

            //删除按钮
            commonUtil.initDeleteBtnEvent({
                callBack: function () {
                    submitList = [];
                    $(".table").find('.check').each(function () {
                        var MaterialID = $(this).find(".MaterialID").text(); //$(this).parents("td").siblings(".MaterialID").text();
                        var ExtrSource = '<%=UserInfo.UserExtrSource %>';
                        submitList.push({
                            MaterialID: MaterialID,
                            ExtrSource: ExtrSource
                        });
                    });
                    if (submitList.length == 0) {
                        swal('请选择要删除的项');
                        return false;
                    }
                    // console.table(submitList);
                    Y.API2('NdwKnockMat', 'Remove',
                        {
                            List: submitList
                        }
                        , function (data) {
                            layer.closeAll('dialog');
                            if (data.Success == false) {
                                swal('删除失败', data.Message, 'error');
                            } else {
                                swal('删除成功', '该信息已被你永久删除', 'success');
                                loadList();
                            }
                        });
                }
            });
            //导入
            $(".btns-container").on("click", '#importBtn', function () {
                $.ImportExcelTemplate({
                    filetype: 'NDWKNOCKMATSET',
                    filename: '淘汰品设置',
                    //conditions: getConditions(),
                    action: 'ImportTemplate',
                    state: 'hasInfo',
                    after: function () {
                        //回调方法
                        loadList();
                    }
                });
            });



        });
    </script>
</asp:Content>




